package com.tungse.copyExample;

public class 深拷贝 {

    public static void main(String[] args) throws CloneNotSupportedException {
        Address address = new Address("Beijing");
        Employee employee1 = new Employee("John", address);
        Employee employee2 = (Employee) employee1.clone();

        System.out.println("employee1 name: " + employee1.getName() + ", city: " + employee1.getAddress().getCity());
        System.out.println("employee2 name: " + employee2.getName() + ", city: " + employee2.getAddress().getCity());

        // 修改 employee2 的地址
        employee2.getAddress().setCity("Shanghai");

        System.out.println("After modification:");
        System.out.println("employee1 name: " + employee1.getName() + ", city: " + employee1.getAddress().getCity());
        System.out.println("employee2 name: " + employee2.getName() + ", city: " + employee2.getAddress().getCity());
    }

}

